package com.kuang.demo01;

/**
 * @author FHL
 */
public class TestPriority {
    //主线程默认优先级
    public static void main(String[] args) {
System.out.println(Thread.currentThread().getName()+"的优先级为："+Thread.currentThread().getPriority());
        MyPriority myPriority=new MyPriority();
        Thread t1 = new Thread(myPriority);
        Thread t2 = new Thread(myPriority);
        Thread t3 = new Thread(myPriority);
        Thread t4 = new Thread(myPriority);
        //先设置优先级，再启动
        t1.setPriority(1);
        t1.start();
        //MAX_PRIORITY：最大优先级，最大优先级为10
        t2.setPriority(Thread.MAX_PRIORITY);
        t2.start();
        t3.setPriority(8);
        t3.start();
        t4.setPriority(5);
        t4.start();
    }
    static class MyPriority implements Runnable{
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+"优先级为："+Thread.currentThread().getPriority());
        }
    }
}
